package com.gec.service;

import com.gec.dao.UserMapper;
import com.gec.domain.Option;
import com.gec.domain.PageBean;
import com.gec.domain.User;
import org.activiti.engine.impl.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author Aniki
 */
@Service
public class UserServiceImpl implements  UserService{

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<Option> getDeptOptions() {
        return userMapper.queryDeptOptions();
    }

    @Override
    public List<Option> getRoleOptions() {
        return userMapper.queryRoleOptions();
    }

    @Override
    public PageBean getUserList(int page, int limit, Map data) {
        //后面做模糊搜索计算偏移量
        int offset = (page - 1) * limit;
        List<User> list = null;
        //data存入的是模糊搜索关键字数据
        list = userMapper.queryList(data);
        PageBean pBean = new PageBean();
        /**临时写法 后面要改*/
        pBean.setCount(list.size());
        pBean.setList(list);
        return pBean;
    }

    @Override
    public void delUser(String id) {
       userMapper.delUser(id);
    }

    @Override
    public void saveUser(User user) {
        userMapper.saveUser(user);
    }

    @Override
    public void saveRoleId(String id,String role) {
        userMapper.saveRoleId(id,role);
    }

    @Override
    public void updateUser(User user) {
        userMapper.updateUser(user);
    }

    @Override
    public User getUser(String id) {

        return userMapper.getUser(id);
    }

    @Override
    public User getUserByName(String username) {

        return userMapper.getUserByName(username);
    }
}
